<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>Lobby System - Forge Networking Remastered</title>
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
  
  <script>
    // Current page data
    var mkdocs_page_name = "Lobby System";
    var mkdocs_page_input_path = "lobby.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> Forge Networking Remastered</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
	<ul class="current">
	  
          
            <li class="toctree-l1">
		
    <span class="caption-text">Home</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="..">User Manual (Forge Networking Remastered)</a>
                </li>
                <li class="">
                    
    <a class="" href="../authoritative-design/">Authoritative Design</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Getting Started</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../GettingStarted/getting-started/">Getting Started</a>
                </li>
                <li class="">
                    
    <a class="" href="../GettingStarted/basic-moving-cube-example/">Basic Moving Cube Example</a>
                </li>
                <li class="">
                    
    <a class="" href="../GettingStarted/basic-rpc-example/">Basic RPC Example</a>
                </li>
                <li class="">
                    
    <a class="" href="../GettingStarted/basic-instantiation-example/">Basic Instantiation Example</a>
                </li>
                <li class="">
                    
    <a class="" href="../GettingStarted/jump-start-guide/">Jump Start Guide</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Network Contract Wizard (NCW)</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../NetworkContractWizard/network-contract-wizard-ncw/">Network Contract Wizard (NCW)</a>
                </li>
                <li class="">
                    
    <a class="" href="../NetworkContractWizard/extending-generated-classes/">Extending Generated Classes</a>
                </li>
                <li class="">
                    
    <a class="" href="../NetworkContractWizard/name-collision-issues/">Name Collision Issues</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Network Object</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../NetworkObject/changing-ownership/">Changing Ownership</a>
                </li>
                <li class="">
                    
    <a class="" href="../NetworkObject/destroying-the-network-object/">Destroying the Network Object</a>
                </li>
                <li class="">
                    
    <a class="" href="../NetworkObject/fields/">Fields</a>
                </li>
                <li class="">
                    
    <span class="caption-text">Remote Procedure Calls (RPCs)</span>
    <ul class="subnav">
                <li class="toctree-l3">
                    
    <a class="" href="../NetworkObject/RemoteProcedureCalls/remote-procedure-calls/">Remote Procedure Calls</a>
                </li>
                <li class="toctree-l3">
                    
    <a class="" href="../NetworkObject/RemoteProcedureCalls/buffered-rpcs/">Buffered RPCs</a>
                </li>
                <li class="toctree-l3">
                    
    <a class="" href="../NetworkObject/RemoteProcedureCalls/sending-rpc-to-a-single-player/">Sending RPC to a Single Player</a>
                </li>
                <li class="toctree-l3">
                    
    <a class="" href="../NetworkObject/RemoteProcedureCalls/rpcargs-and-rpcinfo-structs/">RpcArgs and RpcInfo Structs</a>
                </li>
                <li class="toctree-l3">
                    
    <a class="" href="../NetworkObject/RemoteProcedureCalls/rpc-validation-by-server/">RPC Validation by Server</a>
                </li>
                <li class="toctree-l3">
                    
    <a class="" href="../NetworkObject/RemoteProcedureCalls/replacing-previous-buffered-rpcs/">Replacing Previous Buffered RPCs</a>
                </li>
                <li class="toctree-l3">
                    
    <a class="" href="../NetworkObject/RemoteProcedureCalls/clearing-buffered-rpcs/">Clearing Buffered RPCs</a>
                </li>
    </ul>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Unity Integration</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../UnityIntegration/gameobject-execution-order/">GameObject Execution Order</a>
                </li>
                <li class="">
                    
    <a class="" href="../UnityIntegration/network-instantiation/">Network Instantiation</a>
                </li>
                <li class="">
                    
    <a class="" href="../UnityIntegration/threading-in-unity/">Threading in Unity</a>
                </li>
                <li class="">
                    
    <a class="" href="../UnityIntegration/main-threading-rpcs/">Main Threading RPCs</a>
                </li>
                <li class="">
                    
    <a class="" href="../UnityIntegration/running-unity-specific-code-on-the-main-thread/">Running Unity specific code on the main thread</a>
                </li>
                <li class="">
                    
    <a class="" href="../UnityIntegration/network-start/">Unity Integration Network Start</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Basic Network Samples</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../BasicNetworkSamples/server-hosting-code/">Server Hosting Code</a>
                </li>
                <li class="">
                    
    <a class="" href="../BasicNetworkSamples/client-connecting-code/">Client Connecting Code</a>
                </li>
                <li class="">
                    
    <a class="" href="../BasicNetworkSamples/server-disconnect-client-code/">Server Disconnect Client Code</a>
                </li>
                <li class="">
                    
    <a class="" href="../BasicNetworkSamples/ban-client-code/">Ban Client Code</a>
                </li>
                <li class="">
                    
    <a class="" href="../BasicNetworkSamples/send-binary-frame/">Send Binary Frame</a>
                </li>
                <li class="">
                    
    <a class="" href="../BasicNetworkSamples/send-file/">Send File</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Scene Navigation</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../SceneNavigation/loading-scenes/">Loading Scenes</a>
                </li>
                <li class="">
                    
    <a class="" href="../SceneNavigation/scene-events/">Scene Events</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">NetWorker</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../NetWorker/temporarily-blocking-connections/">Temporarily Blocking Connections</a>
                </li>
                <li class="">
                    
    <a class="" href="../NetWorker/thread-safe-player-iteration/">Thread Safe Player Iteration</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Master Server</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../MasterServer/quick-start/">Master Server Quick Start</a>
                </li>
                <li class="">
                    
    <a class="" href="../MasterServer/connecting-to-master-server/">Connecting to Master Server</a>
                </li>
                <li class="">
                    
    <a class="" href="../MasterServer/getting-host-list/">Getting Host List From Master Server</a>
                </li>
                <li class="">
                    
    <a class="" href="../MasterServer/windows-server-firewall-setup/">Windows Server Firewall Setup</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Web Server</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../WebServer/jumpstart/">Web Server Jumpstart</a>
                </li>
                <li class="">
                    
    <a class="" href="../WebServer/extending-with-mvc/">Web Server Extending With MVC</a>
                </li>
                <li class="">
                    
    <a class="" href="../WebServer/command-plugins/">Web Server Command Plugins</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <span class="caption-text">Troubleshooting</span>
    <ul class="subnav">
                <li class="">
                    
    <a class="" href="../Troubleshooting/troubleshooting/">Troubleshooting</a>
                </li>
                <li class="">
                    
    <a class="" href="../Troubleshooting/throttling-network-internal/">Throttling Network Internal</a>
                </li>
    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../connection-cycle-events/">Events</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../rewinding/">Rewinding</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../network-logging/">Debugging</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../working-with-multiple-sockets/">Working With Multiple Sockets</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../nat-hole-punching/">NAT Hole Punching</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../lan-discovery/">LAN Discovery</a>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../offline-mode/">Offline Mode</a>
	    </li>
          
            <li class="toctree-l1 current">
		
    <a class="current" href="./">Lobby System</a>
    <ul class="subnav">
            
    <li class="toctree-l2"><a href="#lobby-system">Lobby System</a></li>
    
        <ul>
        
            <li><a class="toctree-l3" href="#using-the-existing-lobby-system">Using the Existing Lobby System</a></li>
        
            <li><a class="toctree-l3" href="#lobby-service-api-calls">Lobby Service API Calls</a></li>
        
            <li><a class="toctree-l3" href="#lobby-system-enhancements">Lobby System Enhancements</a></li>
        
        </ul>
    

    </ul>
	    </li>
          
            <li class="toctree-l1">
		
    <a class="" href="../adding-and-updating-docs/">Contributing</a>
	    </li>
          
        </ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">Forge Networking Remastered</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
    
    <li>Lobby System</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1 id="lobby-system">Lobby System</h1>
<p>The lobby system is a way for you to be able to manage your existing players on your particular server on a global level.</p>
<p><strong>With this system, you are able to do the following:</strong></p>
<ul>
<li>Set Player Name (string)</li>
<li>Set Avatar ID (int)</li>
<li>Set Team ID (int)</li>
<li>Send a message to everyone like the chat system (string)</li>
<li>Kick player</li>
<li>Start game button</li>
</ul>
<p>This system allows us to be able to control the list of players and functionality of those players at runtime. There is a basic dummy lobby master class that will be the default system chosen until overridden with either our custom Lobby Master (unity implementation) or your own Custom Lobby Master. Because of the way it is written for forge, this system does not need to be ran from Unity and can work perfectly fine on your linux builds (more on this later).</p>
<h2 id="using-the-existing-lobby-system">Using the Existing Lobby System</h2>
<p>The existing lobby system is available out of the box to be used in your application. The one thing you want to check is if you are using the MultiplayerMenu and loading into your game then you'll be fine following skipping to step #2.</p>
<ol>
<li>First ensure that whatever network loading sequence you are going with, that the host will call the following code.</li>
</ol>
<pre><code class="csharp">LobbyService.Instance.Initialize(serversocket);
</code></pre>

<p>Where the 'server socket' would be the socket that the host makes when hosting. You can see this being done in the example MultiplayerMenu.cs that is included with Forge Networking.</p>
<ol>
<li>Add the lobby system prefab (LobbySystem.prefab) to your game scene, or wherever you want to include the lobby system to your existing game.</li>
<li>If you don't have an event system &amp; a standalone input module in your scene already, then you would need to make sure they are in there to interact with the lobby items as well.</li>
</ol>
<p>The lobby player item prefab is just a prefab that stores the users name, color, buttons and the like. You are free to modify this prefab to your liking as well as the lobby system itself.</p>
<ol>
<li>
<p>Congratulations you have officially added the lobby system to your game and can start using it! Change your name in your player top let, and start talking in the chat bottom left, change the UI to however you please as well as the prefab.</p>
</li>
<li>
<p>PS- To get better results, make sure in the build settings Multiplayermenu -&gt; <em>Lobby</em> -&gt; Game</p>
</li>
</ol>
<h2 id="lobby-service-api-calls">Lobby Service API Calls</h2>
<p>The lobby service has built in api calls that are currently being used in the LobbyManager. For reason of explaining it further, these api calls can be called from anywhere in code as long as you are connected to a socket. This allows you to change the users name from anywhere other than the built in Lobby system.</p>
<pre><code class="csharp">string newName = &quot;&quot;;
LobbyService.Instance.SetName(newName);

uint playerID = 999; 
//Only the server will actually kick players
LobbyService.Instance.KickPlayer(playerID);

int avatarID = -1;
LobbyService.Instance.SetAvatar(avatarID);

int teamID = -1;
LobbyService.Instance.SetTeamId(teamID);

string chatMessage = &quot;&quot;;
LobbyService.Instance.SendPlayerMessage(chatMessage);
</code></pre>

<p>Here is some examples of what the data structure of sending these api calls would look like. As stated before, these can be called anywhere in your code and your LobbyMaster/LobbyManager would handle the data received from other players.</p>
<p>You can easily grab the list of players by doing the following:</p>
<pre><code class="csharp">List&lt;IClientMockPlayer&gt; currentPlayers = LobbyService.Instance.MasterLobby.LobbyPlayers;
</code></pre>

<p>This list will auto populate with the users that join and leave/disconnect.</p>
<h2 id="lobby-system-enhancements">Lobby System Enhancements</h2>
<p>This section is for advanced users who want to expand the lobby system past what is already there for further functionality.</p>
<p>Please take a look at the following classes:
LobbyManager.cs
LobbyPlayer.cs
LobbyPlayerItem.cs</p>
<h3 id="lobby-player-manager">Lobby Player Manager</h3>
<p>The lobby player manager is an example of how you would expand the lobby system itself. Right now it implements the functionality of ILobbyMaster and replaces the mock lobby system with this one during setup. You'll see that it replaces it in SetupComplete() with the following code.</p>
<pre><code class="csharp">LobbyService.Instance.SetLobbyMaster(this);
</code></pre>

<p>SetupComplete() also creates the player item for himself as well as for the already connected players.</p>
<p>You'll notice that you can modify the data however you please and expand on it given the Interface API that is implemented because of the system. If you want to fully understand how the implementation is done, please take a further in-depth look at LobbyService.cs (which we will not cover in this documentation at the moment as it is a lot to go over).</p>
<h3 id="lobby-player">Lobby Player</h3>
<p>The purpose of the lobby player is to implement the IClientMockPlayer which will allow you to implement the basic data that we require for the lobby system to work and expand on it with your own custom data. Just note that if you want that data to be synced properly for any additional logic, you would have to implement the code to be in the lobby manager as well as the LobbyService, otherwise you can always sync the data from other networked objects to the lobby manager with RPC's as well. We will have to revisit this to help make expanding the player data, but just or now I recommend taking a look at the way the data is structured and used in the Lobby Manager in order to populate it as well as the Lobby Service.</p>
<p>The Lobby Player is used extensively on our Lobby Manager to store the current state of a given player.</p>
<h3 id="lobby-player-item">Lobby Player Item</h3>
<p>The lobby player item prefab is used to populate itself with the data of a given player passed in. This is mostly just a ui helper and is not necessary for the player to exist as the lobby system itself will always have all the current players. For demonstration purposes we have included a simple prefab that is being populated in the provided lobby system included with Forge Networking. You are free to populate and change the ui however you please with this data passed in.</p>
<p>We store a reference to the Lobby system itself, but you can easily do other ways of sending the button calls to your own custom lobby system by passing in the actions and the like. This way you would remove the need to have the lobby system being stored as a reference in every lobby player item. The reason we stuck with this format is to just showcase the ease of expanding this item with future features that we plan on adding.</p>
<h3 id="start-game">Start Game</h3>
<p>The start game button sends all the players to the Game scene. How this is setup in build settings. </p>
<p>MultiplayerMenu -&gt; Lobby Scene -&gt; Game </p>
<p>Here is the script of Start Game, if you want to use it in other applications.</p>
<pre><code class="csharp">using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StartGame : MonoBehaviour
{
public void startGame (int Levelnum)
    { 
        Application.LoadLevel(Levelnum);
    }
}
</code></pre>

<h3 id="create-your-own-lobby-easier-way">Create Your Own Lobby (Easier way)</h3>
<p>1) Create a new scene.
2) Add the LobbySystem Prefab.
3) Change the UI, Change the buttons and edit/copy off of the LobbySystem Prefab.
4) make sure the scripts in the LobbySystem prefab go into the desired area in the scene as well as the Inspector (Button scripts go in the button scripts, etc).
5) add it to MultiplayerMenu -&gt; <em>Lobby</em> -&gt; Game</p>
<h3 id="lobby-scene">Lobby Scene</h3>
<p>This Lobby can be used for your game or used as a reference for you to make your own Lobby. This is the Game-Scene.
<img alt="Lobby Scene" src="https://raw.githubusercontent.com/BeardedManStudios/ForgeNetworkingRemastered/develop/docs/mkdocs/docs/images/Lobby-Scene-View.png" /></p>
<h3 id="lobby-overview">Lobby Overview</h3>
<p>This system allows us to be able to control the list of players and functionality of those players at runtime. There is a basic dummy lobby master class that will be the default system chosen until overridden with either our custom Lobby Master (unity implementation) or your own Custom Lobby Master. Because of the way it is written for forge, this system does not need to be ran from Unity and can work perfectly fine on your linux builds (more on this later).</p>
<h3 id="to-be-continued">To Be Continued</h3>
<p>As the lobby system is a great system to add to your game, we are very open to suggestions that can add further features to this as well as give the users the ability to chime in over Discord. As we add more features expect this documentation to cover that and expand.</p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../adding-and-updating-docs/" class="btn btn-neutral float-right" title="Contributing">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../offline-mode/" class="btn btn-neutral" title="Offline Mode"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
      
        <span><a href="../offline-mode/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../adding-and-updating-docs/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>

</body>
</html>
